package com.example.xgakj.newterminal.ui.framents;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.xgakj.newterminal.R;
import com.example.xgakj.newterminal.base.BaseFragment;
import com.example.xgakj.newterminal.base.Parameters;
import com.example.xgakj.newterminal.beans.AlarmTable;
import com.example.xgakj.newterminal.ui.activities.AlarmRecordActivity;
import com.socks.library.KLog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class AlarmDetailFragment extends BaseFragment {


    @BindView(R.id.tv_ID)
    TextView tvID;
    @BindView(R.id.tv_dateOn)
    TextView tvDateOn;
    @BindView(R.id.tv_custId)
    TextView tvCustId;
    @BindView(R.id.tv_areaName)
    TextView tvAreaName;
    @BindView(R.id.tv_jqneirong)
    TextView tvJqneirong;
    @BindView(R.id.tv_jingqingID)
    TextView tvJingqingID;
    @BindView(R.id.tv_fangqu)
    TextView tvFangqu;
    @BindView(R.id.tv_note)
    TextView tvNote;
    @BindView(R.id.tv_ifOK)
    TextView tvIfOK;
    @BindView(R.id.tv_disposal)
    TextView tvDisposal;
    @BindView(R.id.tv_clientOK)
    TextView tvClientOK;
    @BindView(R.id.tv_itype)
    TextView tvItype;
    Unbinder unbinder;
    private Bundle bundle;
    private AlarmTable alarmTable;

    public AlarmDetailFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        KLog.d("onCreate");
        bundle = getArguments();
        if (bundle != null) {
            alarmTable = (AlarmTable) bundle.getSerializable(Parameters.ALARM_BEAN);
            KLog.d(alarmTable.toString());
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_alarm_detail, container, false);
        unbinder = ButterKnife.bind(this, view);
        initViews(alarmTable);
        if(getActivity() instanceof AlarmRecordActivity){
            ((AlarmRecordActivity)getActivity()).setBtnVisible(View.INVISIBLE);
        }

        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if(getActivity() instanceof AlarmRecordActivity){
            ((AlarmRecordActivity)getActivity()).setBtnVisible(View.VISIBLE);
        }
        unbinder.unbind();
    }
    private void initViews(AlarmTable table) {
//        tvID.setText(table.getId());
//        tvDateOn.setText(table.getDateon());
//        tvCustId.setText(table.getCustid());
//        tvAreaName.setText(table.getPartid());
        tvJqneirong.setText(table.getJqneirong());
//        tvJingqingID.setText(table.getJingqingid());
//        tvFangqu.setText(table.getFangqu());
//        tvNote.setText(table.getNote());
//        tvIfOK.setText(table.getIfok().equals("0") ? "否" : "是");
//        tvDisposal.setText(table.getDisposal());
//        setClient(table.getClientok());
//        setType(table.getItype());
    }

    private void setClient(String s) {
        switch (s) {
            case "0":
                tvClientOK.setText("未处理");
                break;
            case "1":
                tvClientOK.setText("处理中");
                break;
            case "2":
                tvClientOK.setText("已处理");
                break;
            default:
        }
    }

    private void setType(String s) {
        switch (s) {
            case "0":
                tvItype.setText("文字报警");
                break;
            case "1":
                tvItype.setText("视频报警");
                break;
            default:

        }
    }
}
